/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cx1.service.impl;

import com.microtripit.mandrillapp.lutung.MandrillApi;
import com.microtripit.mandrillapp.lutung.model.MandrillApiError;
import com.microtripit.mandrillapp.lutung.view.MandrillMessage;
import com.microtripit.mandrillapp.lutung.view.MandrillMessage.MessageContent;
import com.microtripit.mandrillapp.lutung.view.MandrillMessageStatus;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.lang.StringUtils;
import org.cx1.model.Inquiry;
import org.cx1.model.Invite;
import org.cx1.model.Listing;
import org.cx1.model.User;
import org.cx1.model.utils.ServiceResponse;
import org.cx1.model.utils.SystemProperties;
import org.cx1.service.api.IEmailService;
import org.cx1.service.api.IListingService;
import org.cx1.service.api.IUserService;
import org.cx1.service.utils.MailjetClient;
import org.cx1.service.utils.MandrillClient;

/**
 *
 * @author ECH
 */
public class MEmailService implements IEmailService {

    private IUserService userService = new DUserService();    
    private IListingService listingService = new DListingService();
    
    private MandrillClient mandrillClient = new MandrillClient();
    private MailjetClient mailjetClient = new MailjetClient();
    
    @Override
    public ServiceResponse<Boolean> sendEmail(String toEmail, String subject, String body) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;           
        try {                                                
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {              
                
                String fromEmail = "jess@rentpad.me";
                String fromName = "Jessica Garcia";
                
                //CX: Mandrill
                if (SystemProperties.EMAIL_SENDER == 1) {                    
                    mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }
                //CX: Mailjet
                else if (SystemProperties.EMAIL_SENDER == 2) {
                    mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }                
            }   
            success = true;
            response.setResponse(success);
            response.setSuccessful(true); 
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }
    
    @Override
    public ServiceResponse<Boolean> sendInvite1(String name, String toEmail) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;           
        try {                                                
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {                
                String fromEmail = "jess@rentpad.me";
                String fromName = "Jessica Garcia";
                String subject = "Are you looking for tenants to rent out your condo, apartment, house or room?";
                //String subject = "Get tenants to rent out your Condo, Apartment, House or Room";
                String body = "Prospective tenants are waiting for you.<br>" +
                                "<br>" +
                                "People from all over the world visit http://rentpad.com.ph in search for the right place to rent in Metro Manila and Metro Cebu and Davao" + 
                                "TENS OF THOUSANDS of them every month!<br>" +
                                "<br>" +
                                "The good news for you is you can take advantage of this as you can post here your condos, apartments, houses and rooms for rent, and get found by people looking for exactly what you offer. Here's a link to do that: <br>" +
                                "<br>" +
                                "--> <a href='http://goo.gl/nBXhv2'>http://rentpad.com.ph/signup.htm</a><br>" +
                                "<br>" +
                                "Our website is visited by the new generation (internet generation) of renters, like professionals who want to move closer to their work, families relocating, travellers who seek a place to stay, as well as international movers coming from America, Europe and other continents.<br>" +
                                "<br>" +
                                "Do your target tenants fall to any of these? Then you're welcome to join us and post your properties!<br>" +
                                "<br>" +
                                "--> <a href='http://goo.gl/nBXhv2'>http://rentpad.com.ph/signup.htm</a><br>" +
                                "<br>" +
                                "See you there! =) <br>" +
                                "<br>" +
                                "<br>" +
                                "The Rentpad Team<br>" +                           
                                "<img src=\"http://rentpad.com.ph/img/rentpad-logo-1.png\" alt=\"Rentpad Logo\" width=\"140px\" height=\"30px\"/><br><br>" + 
                                "To stop getting emails like this, <a href=\"http://rentpad.com.ph/invite.htm?a=25&email="+toEmail+"\">click here to unsubscribe</a>.";
                
                //subject = "test mailjet";
                //body = "test 123";
                
                /*                
                String subject = "Get Tenants to Rent Out your Condo, Apartment, House or Room";
                String body = "People come to <b><a href='http://rentpad.com.ph'>Rentpad.com.ph</a></b> looking for a place to rent as our website Rentpad.com.ph, is a place dedicated entirely to rental properties.<br>" +
                                "Sounds like a good place for you to find tenants?<br> You can post here your condos, apartments, houses or rooms that are for rent.<br><br>To sign up and post some of your properties, here's a link below:" +
                                "<br><br>" +
                                "<a href='http://rentpad.com.ph/join'>http://Rentpad.com.ph/join</a>\n" +
                                "<br><br>" +
                                "Our website is visited by the <b>new generation (internet generation)</b> of renters; professionals who want to move closer to their work, travellers who seek a place to stay online, as well as international movers coming from the Americas, Europe and other continents. \n" +
                                "<br><br>" +
                                "Do your target tenants fall to any of these?\n" +
                                "<br><br>" +
                                "You're welcome to join us --> <a href='http://rentpad.com.ph/join'>http://Rentpad.com.ph/join</a>\n" +
                                "<br><br>" +
                                "See you there! =)\n" +
                                "<br><br><br>" +
                                "Thank YOU,\n" +
                                "<br>" +                        
                                "--\n" +
                                "<br>" +
                                "Jessica and the Rentpad Team\n";
                */
                
                //CX: Mandrill
                if (SystemProperties.EMAIL_SENDER == 1) {                    
                    mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body);
                }
                //CX: Mailjet
                else if (SystemProperties.EMAIL_SENDER == 2) {
                    mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body);
                }                 
            }   
            success = true;
            response.setResponse(success);
            response.setSuccessful(true); 
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }
    
    @Override
    public ServiceResponse<Boolean> sendInvite2(String name, String email) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {                           
            //CX: deprecated
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }
    
    @Override
    public ServiceResponse<Boolean> sendInviteConfirmation(Invite invite) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try { 
            //CX: gay            
            /*
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {     
                String toEmail = invite.getEmail();                  
                String fromEmail = "team@rentpad.me";
                String fromName = "Rentpad Team";
                String subject = "Rentpad Invite Confirmation";
                String body = "Hallo "+invite.getName()+",<br><br>Welcome Aboard!<br><br>You will receive an email form us when your account is already created.<br>Once you get your account, you can start posting your rental properties and get more leads and tenants. See you there!<br><br>All the best,<br>The Rentpad Team<br><br>If you wish to unsubscribe from these notifications, please let us know via team@rentpad.me";
                        
                //CX: Mandrill
                if (SystemProperties.EMAIL_SENDER == 1) {                    
                    mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body);
                }
                //CX: Mailjet
                else if (SystemProperties.EMAIL_SENDER == 2) {
                    mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body);
                }  
            }  
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);   
            */
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }

    @Override 
    public ServiceResponse<Boolean> sendPostListingReminder(String name, String email) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {   
            //CX: deprecated
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }
    
    @Override
    public ServiceResponse<Boolean> sendInquiry(Inquiry inquiry) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {            
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {                
                //CX: get listing id
                String listingID = inquiry.getListingID();
                ServiceResponse<Listing> sr1 = listingService.read(listingID);

                //CX: get owner id
                if (sr1.isSuccessful() && sr1.getResponse() != null) {
                    Listing listing = sr1.getResponse();
                    String creatorID = listing.getCreatorID();

                    //CX: get user
                    if (!StringUtils.isEmpty(creatorID)) {
                        ServiceResponse<User> sr2 = userService.read(creatorID);

                        //CX: send email
                        if (sr2.isSuccessful() && sr2.getResponse() != null) {
                            User creator = sr2.getResponse();

                            String toEmail = creator.getEmail();
                            String fromEmail = "team@rentpad.me";
                            String fromName = "Rentpad Team";
                            String subject = "Inquiry from " + inquiry.getName() + " for \"" + listing.getTitle() +"\"";
                            String body = "Hi "+creator.getFirstName()+",<br><br>"+inquiry.getName()+" inquired about your property on Rentpad: <a href=\"http://rentpad.com.ph/listing.htm?a=2&id="+listingID+"\">" + listing.getTitle() + "</a><br>Use the contact details below to reach your prospective tenant (replying to this email won't reach your client):<br><br>Contact Details: <b>"+ inquiry.getEmail() +",  "+ inquiry.getPhone() +"</b><br><br>Message: " + inquiry.getMessage() + "<br><br><br>Boost your property to get more inquiries. Click here to learn how: --> <a href=\"http://goo.gl/G5g4kl\">http://rentpad.com.ph/rentpad-featured-properties</a><br><br><br>Happy Renting!<br>The Rentpad Team<br><img src=\"http://rentpad.com.ph/img/rentpad-logo-1.png\" alt=\"Rentpad Logo\" width=\"140px\" height=\"30px\"/><br><br>If you wish to unsubscribe from these notifications, please let us know via team@rentpad.me";

                            //CX: Mandrill
                            if (SystemProperties.EMAIL_SENDER == 1) {                    
                                mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                            }
                            //CX: Mailjet
                            else if (SystemProperties.EMAIL_SENDER == 2) {
                                mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                            } 
                        }
                    }
                }
            }            
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);            
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }

    @Override
    public ServiceResponse<Boolean> sendPostListingConfirmation(String listingTitle, String name, String toEmail) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {            
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {    
                String subjectName = "";
                String htmlName = "";
                if (!StringUtils.isEmpty(name)) {
                    subjectName = name + ", ";
                    htmlName = name;
                }
                
                String fromEmail = "team@rentpad.me";
                String fromName = "Rentpad Team";
                String subject = "Your property \""+listingTitle+"\" is now active at Rentpad.com.ph";
                String body = "Hi "+htmlName+"!<br><br>Your property \""+listingTitle+"\" is successfully posted to Rentpad.<br><br>If you want to edit the info and photos of your property, just navigate to the \"Listings Manager\" page after logging in.<br><br>You can follow this link to view your properties: http://rentpad.com.ph/account.htm#manager<br><br>All the best,<br>Rentpad Team<br><br>";

                //CX: Mandrill
                if (SystemProperties.EMAIL_SENDER == 1) {                    
                    mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }
                //CX: Mailjet
                else if (SystemProperties.EMAIL_SENDER == 2) {
                    mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }                
            }
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);            
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }

     @Override
    public ServiceResponse<Boolean> sendPostListingApproved(String listingTitle, String name, String toEmail) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {            
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {    
                String subjectName = "";
                String htmlName = "";
                if (!StringUtils.isEmpty(name)) {
                    subjectName = name + ", ";
                    htmlName = name;
                }
                
                String fromEmail = "jess@rentpad.me";
                String fromName = "Jessica Garcia";
                String subject = "Your posting \""+listingTitle+"\" is verified and now active at Rentpad.com.ph";
                String body = "Hi "+htmlName+"!<br><br>Your property \""+listingTitle+"\" is verified and successfully posted to Rentpad.<br><br>If you want to edit the info and photos of your property, just navigate to the \"Listings Manager\" page after logging in.<br><br>You can follow this link to view your properties: http://rentpad.com.ph/account.htm#manager<br><br>All the best,<br>Jessica and the Rentpad Team<br><br><img src=\"http://rentpad.com.ph/img/rentpad-logo-1.png\" alt=\"Rentpad Logo\" width=\"140px\" height=\"30px\"/>";

                //CX: Mandrill
                if (SystemProperties.EMAIL_SENDER == 1) {                    
                    mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }
                //CX: Mailjet
                else if (SystemProperties.EMAIL_SENDER == 2) {
                    mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }                
            }
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);            
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }

    @Override
    public ServiceResponse<Boolean> sendPostListingRejected(String listingTitle, String name, String toEmail) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {            
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {    
                String subjectName = "";
                String htmlName = "";
                if (!StringUtils.isEmpty(name)) {
                    subjectName = name + ", ";
                    htmlName = name;
                }
                
                String fromEmail = "jess@rentpad.me";
                String fromName = "Jessica Garcia";
                String subject = "Could not verify your posting \""+listingTitle+"\"";
                String body = "Hi "+htmlName+",<br><br>I could not verify your posting \""+listingTitle+"\".<br><br>For me to approve your posting, make sure to: <br>1. Fill out all the required fields<br>2. Place the correct price/rate format<br>3. Upload ACTUAL photos that represent the property (not drawings/graphics, and make sure they have no watermarks of other websites)<br>4. Make sure this posting has no duplicates <br><br>To edit the info and photos of your posting, just navigate to the \"Listings Manager\" page after logging in.<br><br>You can follow this link to view/edit your properties: http://rentpad.com.ph/account.htm#manager<br><br>If you need any help, just let me know =)<br><br>All the best,<br>Jessica and the Rentpad Team<br><br><img src=\"http://rentpad.com.ph/img/rentpad-logo-1.png\" alt=\"Rentpad Logo\" width=\"140px\" height=\"30px\"/>";

                //CX: Mandrill
                if (SystemProperties.EMAIL_SENDER == 1) {                    
                    mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }
                //CX: Mailjet
                else if (SystemProperties.EMAIL_SENDER == 2) {
                    mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }                
            }
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);            
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }
    
    
    @Override
    public ServiceResponse<Boolean> sendListingFeatured(String listingTitle, String name, String toEmail) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {            
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {    
                String subjectName = "";
                String htmlName = "";
                if (!StringUtils.isEmpty(name)) {
                    subjectName = name + ", ";
                    htmlName = name;
                }
                
                String fromEmail = "jess@rentpad.me";
                String fromName = "Jessica Garcia";
                String subject = name + ", Rentpad featured your posting \""+listingTitle+"\"!";
                String body = "Hi "+htmlName+",<br><br>Congratulations! Your posting \""+listingTitle+"\" is featured for the week as the result of having wonderful photos and proper descriptions.<br><br>This is free advertising awarded to you wich is valued at Php 497. <br>Check it out on our homepage --> http://rentpad.com.ph<br><br>Keep it up to get more rewards in the future!<br><br>All the best,<br>Jessica and the Rentpad Team<br><br><img src=\"http://rentpad.com.ph/img/rentpad-logo-1.png\" alt=\"Rentpad Logo\" width=\"140px\" height=\"30px\"/>";

                //CX: Mandrill
                if (SystemProperties.EMAIL_SENDER == 1) {                    
                    mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }
                //CX: Mailjet
                else if (SystemProperties.EMAIL_SENDER == 2) {
                    mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }                
            }
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);            
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }
    
    @Override
    public ServiceResponse<Boolean> sendSignupConfirmation(String name, String toEmail, String password) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {            
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {   
                String subjectName = "";
                String htmlName = "";
                if (!StringUtils.isEmpty(name)) {
                    subjectName = name + ", ";
                    htmlName = name;
                }
                                  
                String fromEmail = "team@rentpad.me";
                String fromName = "Rentpad Team";
                String subject = subjectName + "your account is now activated";
                String body = "Welcome Aboard "+htmlName+"!<br><br>Your account is ready. You can now start posting your rental properties and start attracting more clients online.<br><br>To post your rental property, login to your Rentpad account using the details below and then navigate to Listings Manager under your account page.<br>You can find that on the upper left corner of the header.<br><br>Here are your login details.<br>Username: "+toEmail+"<br>Password: "+password+"<br><br>Login to Rentpad using this link http://rentpad.com.ph/login.htm<br><br>And you can post properties using this link (make sure you're logged in first): http://rentpad.com.ph/post<br><br>Also, make sure you follow our posting guidelines: http://rentpad.com.ph/rentpad-rules-of-posting<br><br>Happy posting!<br><br>Note: you can always change your password under the account page.<br><br>All the best,<br>Rentpad Team<br><br>";
                        
                //CX: Mandrill
                if (SystemProperties.EMAIL_SENDER == 1) {                    
                    mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }
                //CX: Mailjet
                else if (SystemProperties.EMAIL_SENDER == 2) {
                    mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }  
            }            
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);            
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }
    
    @Override
    public ServiceResponse<Boolean> sendListingExpiredCheck(String listingID, String listingTitle, String name, String toEmail) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {         
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {   
                String subjectName = "";
                String htmlName = "";
                if (!StringUtils.isEmpty(name)) {
                    subjectName = name + ", ";
                    htmlName = name;
                }
                
                String fromEmail = "team@rentpad.me";
                String fromName = "Rentpad Team";
                String subject = "Is this property still available? \"" + listingTitle + "\"";
                String body = "Hi "+htmlName+",<br><br>Action required- choose between \"Mark as Available\" or \"Mark as NOT Available\"<br><br>Just checking if this property is still available: \"<a href=\"http://rentpad.com.ph/listing.htm?a=2&id="+listingID+"\"><b>" + listingTitle + "</b></a>\"<br><br>It's been a while since you posted this property and for the benefit of the whole community, we would like to make sure that your property is still available for rent:<br><br>Click to Mark as NOT Available (ie. if there is a tenant already): <a href=\"http://rentpad.com.ph/listing.htm?a=3004&id="+listingID+"\"><img src=\"http://rentpad.com.ph/img/btn-mark-not-available.jpg\" title=\"Mark as NOT Available\" alt=\"Mark as NOT Available\" width=\"200px\" height=\"30px;\"/></a><br><br>Or<br><br>Click to Mark as still available:  <a href=\"http://rentpad.com.ph/listing.htm?a=3003&id="+listingID+"\"><img src=\"http://rentpad.com.ph/img/btn-mark-available.jpg\" title=\"Mark as Available\" alt=\"Mark as Available\" width=\"200px\" height=\"30px;\"/></a><br><br>Note: You can always edit the availabilities of all your properties using the Listings Manager under your Account Page via http://rentpad.com.ph/account.htm<br><br>All the best,<br>The Rentpad Team<br><img src=\"http://rentpad.com.ph/img/rentpad-logo-1.png\" alt=\"Rentpad Logo\" width=\"140px\" height=\"30px\"/><br><br>For questions, suggestions and feedback, please let us know via team@rentpad.me";
                
                //CX: Mandrill
                if (SystemProperties.EMAIL_SENDER == 1) {                    
                    mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }
                //CX: Mailjet
                else if (SystemProperties.EMAIL_SENDER == 2) {
                    mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }
            }     
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);  
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }    
    
    @Override
    public ServiceResponse<Boolean> sendLeadGenerated(String name, String genEmail, String description) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {         
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {                     
                String fromEmail = "team@rentpad.me";
                String fromName = "Rentpad Team";
                String subject = "Lead Gen: " + new Date();
                String body = "Name: " + name + " Email: " + genEmail + " Desc: " + description;
                
                //CX: Mandrill
                if (SystemProperties.EMAIL_SENDER == 1) {                    
                    mandrillClient.sendEmail(fromEmail, fromName, "chux18@gmail.com", subject, body, "team@rentpad.me");
                }
                //CX: Mailjet
                else if (SystemProperties.EMAIL_SENDER == 2) {
                    mailjetClient.sendEmail(fromEmail, fromName, "chux18@gmail.com", subject, body, "team@rentpad.me");
                }
            }     
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);  
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }    
    
    
    @Override
    public ServiceResponse<Boolean> sendLoginDetails(String email) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {            
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {   
                if (!StringUtils.isEmpty(email)) {
                    ServiceResponse<User> response1 = this.userService.readByEmail(email);
                    User user = response1.getResponse();                    
                    String name = user.getFirstName();
                    String password = user.getPassword();
                    
                    String subjectName = "";
                    String htmlName = "";
                    if (!StringUtils.isEmpty(name)) {
                        subjectName = name + ", ";
                        htmlName = name;
                    }
                
                    String toEmail = email;
                    String fromEmail = "team@rentpad.me";
                    String fromName = "Rentpad Team";
                    String subject = htmlName + ", here are your Rentpad login details";
                    String body = "Hello "+htmlName+"!<br><br>Here are your login details.<br><br>Username: "+toEmail+"<br>Password: "+password+"<br><br>Login to Rentpad using this link http://rentpad.com.ph/login.htm<br>And you can post properties using this link (make sure you're logged in first): http://rentpad.com.ph/post<br><br>Happy posting!<br><br>Note: you can always change your password under the account page.<br><br>All the best,<br>Rentpad Team<br><br><img src=\"http://rentpad.com.ph/img/rentpad-logo-1.png\" alt=\"Rentpad Logo\" width=\"140px\" height=\"30px\"/>";

                    //CX: Mandrill
                    if (SystemProperties.EMAIL_SENDER == 1) {                    
                        mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                    }
                    //CX: Mailjet
                    else if (SystemProperties.EMAIL_SENDER == 2) {
                        mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                    }                      
                }
            }            
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);            
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }
    
    
    @Override
    public ServiceResponse<Boolean> sendExeptionCaught(String email, String message) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {            
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {   
                if (!StringUtils.isEmpty(email)) {
                
                    String toEmail = email;
                    String fromEmail = "team@rentpad.me";
                    String fromName = "Rentpad Team";
                    String subject = "Exception Caught " + new Date();
                    String body = message;

                    //CX: Mandrill
                    if (SystemProperties.EMAIL_SENDER == 1) {                    
                        mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                    }
                    //CX: Mailjet
                    else if (SystemProperties.EMAIL_SENDER == 2) {
                        mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                    }                      
                }
            }            
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);            
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }
    
    
    @Override
    public ServiceResponse<Boolean> sendNewTransaction(String email, String message) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {            
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {   
                if (!StringUtils.isEmpty(email)) {
                
                    String toEmail = email;
                    String fromEmail = "team@rentpad.me";
                    String fromName = "Rentpad Team";
                    String subject = "New Transaction " + new Date();
                    String body = message;

                    //CX: Mandrill
                    if (SystemProperties.EMAIL_SENDER == 1) {                    
                        mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                    }
                    //CX: Mailjet
                    else if (SystemProperties.EMAIL_SENDER == 2) {
                        mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                    }                      
                }
            }            
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);            
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }

    @Override
    public ServiceResponse<Boolean> sendPropertyFeaturedActive(String listingTitle, String name, String toEmail, String city, String rentalTerm, String startDate, String endDate, String url) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {            
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {    
                String subjectName = "";
                String htmlName = "";
                if (!StringUtils.isEmpty(name)) {
                    subjectName = name + ", ";
                    htmlName = name;
                }
                
                String fromEmail = "team@rentpad.me";
                String fromName = "Rentpad Team";
                String subject = "Well done! \""+listingTitle+"\" is now featured on Rentpad.com.ph";
                String body = "Hello "+htmlName+"!<br><br>Your property <b>\""+listingTitle+"\"</b> is now featured on Rentpad.<br><br>Here are the details:<br><br>Your property is featured in <b>"+city+" search results.</b><br>Placed under <b>"+rentalTerm+"</b> category.<br>Featured from <b>"+startDate+"</b> until <b>"+endDate+"</b>.<br>You can check it out here- "+url+"<br><br>To feature another property, just navigate to this link (make sure you're signed in): http://rentpad.com.ph/account.htm<br>In case you have any questions, we're always here to help you out.<br><br>Have an awesome day ahead!<br><br>All the best,<br>The Rentpad Team<br><br><img src=\"http://rentpad.com.ph/img/rentpad-logo-1.png\" alt=\"Rentpad Logo\" width=\"140px\" height=\"30px\"/>";

                //CX: Mandrill
                if (SystemProperties.EMAIL_SENDER == 1) {                    
                    mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }
                //CX: Mailjet
                else if (SystemProperties.EMAIL_SENDER == 2) {
                    mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }                
            }
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);            
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }

    @Override
    public ServiceResponse<Boolean> sendPropertyFeaturedWarning(String listingTitle, String name, String email) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ServiceResponse<Boolean> sendPropertyFeaturedExpired(String listingTitle, String name, String toEmail) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {            
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {    
                String subjectName = "";
                String htmlName = "";
                if (!StringUtils.isEmpty(name)) {
                    subjectName = name + ", ";
                    htmlName = name;
                }
                
                String fromEmail = "team@rentpad.me";
                String fromName = "Rentpad Team";
                String subject = "Your featured property has ended: \""+listingTitle+"\"";
                String body = "Hello "+htmlName+"!<br><br>Hope your property had a productive time at the top.<br><br>By the way, make sure you also check out our \"Rental Leads\" page found<br>under your account page when you login- it is a free lead generation service from us :)<br><br>Would you like to feature again this property or perhaps a different one?<br><br>Here's a link to do that -> http://rentpad.com.ph/featured.htm?a=21<br><br>Have a great day!<br><br>All the best,<br>The Rentpad Team<br><br><img src=\"http://rentpad.com.ph/img/rentpad-logo-1.png\" alt=\"Rentpad Logo\" width=\"140px\" height=\"30px\"/>";

                //CX: Mandrill
                if (SystemProperties.EMAIL_SENDER == 1) {                    
                    mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }
                //CX: Mailjet
                else if (SystemProperties.EMAIL_SENDER == 2) {
                    mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }                
            }
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);            
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }


    @Override
    public ServiceResponse<Boolean> sendListingBoost(String listingID, String listingTitle, String name, String toEmail) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {         
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {   
                String subjectName = "";
                String htmlName = "";
                if (!StringUtils.isEmpty(name)) {
                    subjectName = name + ", ";
                    htmlName = name;
                }
                
                String fromEmail = "jess@rentpad.me";
                String fromName = "Jessica Garcia";
                String subject = "Make your property stand out on Rentpad: \"" + listingTitle + "\"  ";
                String body = "Hi "+htmlName+",<br><br><br>Are you taking advantage of Rentpad generating 95,000 page views per month?<br><br>Today, Rentpad reaches thousands of renters week in week out coming from all over the world<br>and as a consequence to that the amount of properties posted on also increased.<br><br>Rentpad however gives your property an option to stand out and get noticed quicker by renters.<br><br><br>Here's how --> <a href=\"http://rentpad.com.ph/rentpad-featured-properties\">http://rentpad.com.ph/rentpad-featured-properties</a><br><br>Have a gread day!<br><br><br>All the best,<br>Jessica and The Rentpad Team<br><img src=\"http://rentpad.com.ph/img/rentpad-logo-1.png\" alt=\"Rentpad Logo\" width=\"140px\" height=\"30px\"/><br><br>If you want to unsubscribe from these notifications, just let us know via team@rentpad.me";
                
                //CX: Mandrill
                if (SystemProperties.EMAIL_SENDER == 1) {                    
                    mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }
                //CX: Mailjet
                else if (SystemProperties.EMAIL_SENDER == 2) {
                    mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }
            }     
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);  
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }
       
    @Override
    public ServiceResponse<Boolean> sendListingStats(String listingID, String listingTitle, String name, String toEmail) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {         
            Listing listing = this.listingService.read(listingID).getResponse();
            
            //CX: check if email is enabled
            if (listing != null && SystemProperties.EMAIL_ENABLED == 1) {   
                String subjectName = "";
                String htmlName = "";
                if (!StringUtils.isEmpty(name)) {
                    subjectName = name + ", ";
                    htmlName = name;
                }
                
                String fromEmail = "jess@rentpad.me";
                String fromName = "Jessica Garcia";
                String subject = "Performace of your property \"" + listingTitle + "\" on Rentpad";
                String body = "Hi "+htmlName+",<br><br>Here's how your property is doing so far: <a href=\"http://rentpad.com.ph/listing.htm?a=2&id="+listingID+"\">"+listingTitle+"</a><br><br> # of Impressions: "+listing.getImpressions()+"<br> # of Views: "+listing.getViews()+"<br><br>You can check the stats of your other properties under the Listings Manager on your account page.<br><br>Would you like to boost the performance of your property?<br><br>From piles of other properties on Rentpad, there is a way to stand out from the rest, <br>be seen by more renters thus increase your viewership.<br><br>Here's how --> <a href=\"http://goo.gl/G5g4kl\">http://rentpad.com.ph/rentpad-featured-properties</a> <br><br>All the best,<br>Jessica and The Rentpad Team<br><img src=\"http://rentpad.com.ph/img/rentpad-logo-1.png\" alt=\"Rentpad Logo\" width=\"140px\" height=\"30px\"/><br><br>If you want to unsubscribe from these notifications, just let us know via team@rentpad.me";
                
                //CX: Mandrill
                if (SystemProperties.EMAIL_SENDER == 1) {                    
                    mandrillClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }
                //CX: Mailjet
                else if (SystemProperties.EMAIL_SENDER == 2) {
                    mailjetClient.sendEmail(fromEmail, fromName, toEmail, subject, body, "team@rentpad.me");
                }
            }     
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);  
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }
    
    
    @Override
    public ServiceResponse<Boolean> sendLeadView(String leadID, String name, String email) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {   
            //CX: check if email is enabled
            if (SystemProperties.EMAIL_ENABLED == 1) {   
                
                String fromEmail = "jess@rentpad.me";
                String fromName = "Jessica Garcia";
                String subject = "Lead View " + new Date();
                String body = "leadID: " + leadID + "<br>name: " + name + "<br>email: " + email;
                
                //CX: Mandrill
                if (SystemProperties.EMAIL_SENDER == 1) {                    
                    mandrillClient.sendEmail(fromEmail, fromName, "chux@rentpad.me", subject, body, "team@rentpad.me");
                }
                //CX: Mailjet
                else if (SystemProperties.EMAIL_SENDER == 2) {
                    mailjetClient.sendEmail(fromEmail, fromName, "chux@rentpad.me", subject, body, "team@rentpad.me");
                }
            }     
            success = true;
            response.setResponse(success);
            response.setSuccessful(true);  
        }
        catch (Exception ex) {
            response.setResponse(false);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);      
        } 
        return response;
    }
    
    
    
    public static void main(String argv[]) {
        IEmailService emailService = new MEmailService();
        //emailService.sendInvite1(null, "chux18@yahoo.com");  
        
        //emailService.sendListingFeatured("2 Bedroom with balcony at Seaside Residences", "Chux", "chux18@gmail.com");
        //emailService.sendPostListingApproved("2 Bedroom with balcony at Seaside Residences", "Chux", "chux18@gmail.com");
        
        //emailService.sendPostListingReminder("Chux", "chux18@gmail.com");
        //emailService.sendPostListingConfirmation("2 Bedroom with balcony at Seaside Residences", "Chux", "chux18@gmail.com");
        //emailService.sendSignupConfirmation("Chux", "chux18@gmail.com", "jwSBOl");
        //emailService.sendListingExpiredCheck("45eb4c10-5afa-4781-81e0-2d05d9836225", "Studio Condominium at Grand Soho Makati", "Dagohoy3", "chux18@gmail.com");
        
        //Invite invite = new Invite();
        //invite.setEmail("chux18@gmail.com");
        //invite.setName("Chux");      
        //emailService.sendInviteConfirmation(invite);
        
        //Inquiry inquiry = new Inquiry();
        //inquiry.setName("Gabriel Batistuta");
        //inquiry.setEmail("batis@roma.com");
        //inquiry.setPhone("3546457457");
        //inquiry.setMessage("This is the message");
        //inquiry.setListingID("45eb4c10-5afa-4781-81e0-2d05d9836225");        
        //emailService.sendInquiry(inquiry);
        
        //Featured Active Test
        //String email = "chux18@gmail.com";
        //String name = "Chux";
        //String listingTitle = "One Really Nice Bedroom";
        //String city = "Makati";
        //String rentalTerm = "long term rentals";
        //String startDate  = "March 23, 2014"; 
        //String endDate = "March 29, 2014";
        //String url = "http://rentpad.com.ph/long-term-rentals/makati";        
        //emailService.sendPropertyFeaturedActive(listingTitle, name, email, city, rentalTerm, startDate, endDate, url);
        
        //Boost Email Test
        //emailService.sendListingBoost("45eb4c10-5afa-4781-81e0-2d05d9836225", "2 Bedroom Condominium at The Residences at Greenbelt", "Bogs", "chux18@gmail.com");
        
        //Stats Email Test
        emailService.sendListingStats("45eb4c10-5afa-4781-81e0-2d05d9836225", "Studio Condominium at Grand Soho Makati", "Bogs", "chux18@gmail.com");
        
        
        //emailService.sendPropertyFeaturedExpired("2 Bedroom Condominium at The Residences at Greenbelt", "Bogs", "chux18@gmail.com");
    }

    
}
